package org.leon.service;

import org.leon.pojo.Comment;
import org.leon.repository.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Optional;


@Service
public class CommentService {

    @Autowired
    private CommentRepository commentRepository;

    public void updateComment(String author, Integer id) {
        commentRepository.updateComment(author, id);
    }

    @Cacheable(cacheNames = "commentId")
    public Comment findCommentById(Integer id) {
        Optional<Comment> comment = commentRepository.findById(id);
        if (comment.isPresent()) {
            return comment.get();
        }
        return null;
    }
}
